home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 July
/
EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso
/
earcd
/
biz
/
dbase
/
ax.lha
/
Ax
/
Rexx
/
FTP_DaFTP.ax
< prev
next >
Wrap
Text File
|
1997-03-15
|
9KB
|
362 lines
/*
* Ax ARexx-FTP interface script
* FTP client: DaFTP
* $VER: FTP_DaFTP.ax 1.0 (6.12.96)
*
* Version 1.0
* by Paul A. Schifferer
* Copyright 1996 © Isengard Developments
*
* This script is freely distributable and modifiable. You are authorized to
* modify it to suit your needs. Isengard Developments makes no warranty,
* express or implied, for its usability or reliability in its original or
* modified form.
*
* This script takes an optional list of files to retrieve with the FTP client
* program noted above. If 'files' aren't specified on the command line, the
* script will attempt to interface with Ax, using the ARexx port name "AXFTP"
* to get files. Alternatively, 'files' can be "LIST=filename", which
* specifies the list of files to use (see below). If files are specified on
* the command line for this script, then the first parameter must be the site
* name, the second the base directory, and all subsequent parameters are
* files in the form of 'path/filename' (relative to the base path).
*
* The file list is in the following format:
*
* The first line is the site from which to retrieve the files. The second
* line is the base directory to use, e.g., '/pub/aminet', without the
* trailing slash. This dir should always be an absolute path, i.e., with
* the beginning slash.
*
* All subsequent lines are files to retrieve in the form of 'path/filename',
* e.g., "biz/dbase/Ax.lha". 'path' need not be specified, if the file is
* located in the base directory. Note that all paths should be specified
* relative to the base directory, but this is not a requirement. Absolute
* pathnames may be used.
*
* A line with three hashes ('###') ends the filelist. Everything thereafter
* is ignored.
*/
options results
signal on syntax
signal on error
parse arg files
/*
* Is Ax running?
*/
if (length(files) = 0) & ~show('P',"AX") then do
say "Ax must be running to use this script!"
exit 20
end
/*
* Set up some variables.
*/
clientname = "DaFTP"
scriptname = "FTP_"clientname".ax"
clientpath = "DaFTP"
clientopts = "ICONIFIED"
clientport = "DAFTP.1"
ftpport = ""
/*
* Command variables.
*
* The following variables are commands that would be issued to the FTP client
* program. The construct is simple: "command parameter options". Place
* the client's command portion in the variable <a-cmd>cmd, where <a-cmd> is
* the type of command. This script will place after the command any parameters
* that are necessary. If the command has options to be specified, place them
* in the variable <a-cmd>opts. These will be placed at the end of the command,
* after the parameters.
*
* For example, the "GET" command for DaFTP allows you to specify the transfer
* mode. To set up this command, you would put "GET" in the variable 'getcmd',
* and "BINARY" in the variable 'getopts'. When the command is issued, it
* will be sent to DaFTP as "GET <filename> BINARY".
*
* It's really very simple. If you are having problems with it, just send me
* e-mail <gandalf@hughes.net>, and we'll work it out, okay?
*/
sitecmd = "SITE"
siteopts = ""
connectcmd = "CONNECT"
connectopts = "NOSCAN"
portcmd = ""
portopts = ""
binarycmd = ""
binaryopts = ""
cdcmd = "CD"
cdopts = "NOSCAN"
lcdcmd = "LCD"
lcdopts = ""
getcmd = "GET"
getopts = "BIN"
quitcmd = "QUIT"
quitopts = "FORCE"
/*
* Check if environment var for FTPCLIENT is set and use it. The first line
* in the var would be the full path of the FTP client to use. The second
* line, which is optional, specifies any options to use on the command line
* when starting the client program.
*/
if exists("ENV:FTPCLIENT") then do
if open('fc',"ENV:FTPCLIENT",'R') then do
line = strip(readln('fc'))
if length(line) > 0 then clientpath = line
line = strip(readln('fc'))
if length(line) > 0 then clientopts = line
end
call close('fc')
end
/*
* Start FTP client.
*/
if ~show('P',clientport) then do
say "Starting FTP client..."
address command "Run >NIL: "clientpath clientopts
end
/*
if rc ~= 0 then do
say scriptname": Error" rc "trying to start FTP client '"clientname"'!"
exit 10
end
*/
/*
* Wait for ARexx port to appear (2 minute timeout).
*/
call time('R')
do forever
if show('P',clientport) then leave
call Delay(250)
if time('E') > 120 then do
say scriptname": Timeout waiting for client port '"clientport"'!"
exit 10
end
end
/*
* Set up port #.
*/
address value(clientport)
if length(ftpport) > 0 then do
""portcmd ftpport portopts
end
/*
* Get site name & base dir.
*/
address AXFTP
"Site"
site = result
"BaseDir"
basedir = result
/*
* Connect to site.
*/
address value(clientport)
""sitecmd site siteopts
if result = "0" then do
say scriptname": Site '"site"' not found!"
address AX "ErrorReq" scriptname" ("rc"): Site '"site"' not found!"
address AXFTP "Status" scriptname" ("rc"): Site '"site"' not found!"
exit 10
end
if length(connectcmd) > 0 then do
""connectcmd connectopts
end
if result = "0" then do
say scriptname": Unable to connect to site '"site"'!"
address AX "ErrorReq" scriptname" ("rc"): Unable to connect to site '"site"'!"
address AXFTP "Status" scriptname" ("rc"): Unable to connect to site '"site"'!"
exit 10
end
/*
* Set transfer mode.
*/
if length(binarycmd) > 0 then do
""binarycmd binaryopts
end
/*
* Were files or a filelist specified?
*/
filelist = ""
if length(files) > 0 then do
if upper(substr(files,1,5)) = "LIST=" then do
filelist = word(substr(files,6),1)
c = usefilelist(filelist)
if c ~= 0 then exit c
signal thatsit
end
else do
c = usefiles(files)
if c ~= 0 then exit c
signal thatsit
end
end
/*
* The following code controls interaction with Ax (via the ARexx ports AX and
* AXFTP) and the FTP client to grab files.
*/
/* tell Ax to start FTP thread, if not running */
address AX
"StartFTP"
if result = "0" then do
say scriptname": Unable to start Ax's FTP thread!"
exit 10
end
call time('R')
do forever
if show('P',"AXFTP") then leave
call Delay(250)
if time('E') > 120 then do
say scriptname": Timeout waiting for port 'AXFTP'!"
exit 10
end
end
/*
* Reset file list.
*/
"ResetFilelist"
/*
* Main file retrieval loop.
*/
do forever
address AXFTP
"GetFilename"
file = result
if file = "" then leave
"GetPath ABSOLUTE"
path = result
address AXFTP "Status Changing remote directory to '"path"'..."
address value(clientport) ""cdcmd path cdopts
address AXFTP "Status Retrieving '"file"'..."
address value(clientport) ""getcmd file getopts
if result = "0" then do
address AXFTP "Status Unable to retrieve '"file"'!"
address AX "ErrorReq Unable to retrieve '"file"'!"
end
else do
address AXFTP
"SetFile DOWNLOADED"
"RemoveFile"
end
"NextFile"
end
thatsit:
/*
* Tell FTP client to shut down.
*/
if length(quitcmd) > 0 then do
address value(clientport)
""quitcmd quitopts
end
exit 0
/*
* This procedure lets the script grab files via the FTP client using a file
* list.
*/
usefilelist:
parse arg flist
error = 0
if open('fl',flist,'R') then do
site = strip(readln('fl'))
basedir = strip(readln('fl'))
do while ~eof('fl')
fpath = readln('fl')
if fpath = "###" then leave
if substr(fpath,1,1) = "/" then do /* absolute pathname */
fpath = reverse(fpath)
parse fpath fname "/" fpath
fpath = reverse(fpath)
fname = reverse(fname)
end
else if index(fpath,"/") > 0 then do /* relative pathname is specified */
fpath = reverse(basedir"/"fpath)
parse fpath fname "/" fpath
fpath = reverse(fpath)
fname = reverse(fname)
end
else do
fname = fpath
fpath = basedir
end
address value(clientport)
""cdcmd fpath cdopts
""getcmd fname getopts
end
call close('fl')
end
return error
/*
* This procedure lets the script grab files via the FTP client using files
* specified on the command line.
*/
usefiles:
parse arg site basedir flist
error = 0
do forever
parse var flist fpath flist
if fpath = "" then leave
if substr(fpath,1,1) = "/" then do /* absolute pathname */
fpath = reverse(fpath)
parse fpath fname "/" fpath
fpath = reverse(fpath)
fname = reverse(fname)
end
else if index(fpath,"/") > 0 then do /* relative pathname is specified */
fpath = reverse(basedir"/"fpath)
parse fpath fname "/" fpath
fpath = reverse(fpath)
fname = reverse(fname)
end
else do
fname = fpath
fpath = basedir
end
end
address value(clientport)
""cdcmd fpath cdopts
""getcmd fname getopts
end
return error
syntax:
err = rc
parse source . . . me .
address AX "ErrorReq ARexx error" err "in line" sigl "of" me"."
exit
error:
parse source . . . me .
address AX "ErrorReq Error" rc "in line" sigl "of" me"."